package com.problem.leetcode;

public class Problem169 {
    public int majorityElement(int[] nums) {
        int count = 1;
        int major = nums[0];

        for (int index = 1; index < nums.length; index++) {
            if (nums[index] != major) {
                --count;
            } else {
                ++count;
            }

            if (count == 0) {
                major = nums[index];
                ++count;
            }

        }
        return major;
    }
}
